package com.tac.controller;

import com.tac.common.R;
import com.tac.pojo.SelectCourse;
import com.tac.pojo.SelectCourseDto;
import com.tac.service.SelectCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/selectCourse")
@RestController
public class SelectCourseController {
    @Autowired
    private SelectCourseService selectCourseService;

    //等下可以判定一下曾经有没有选过；

    /**
     * 选课
     * @param sid
     * @param cid
     * @return
     */
    @PostMapping("/insertBySidAndCid")
    public R InsertBySidAndCid(Integer sid,Integer cid){
        R r = selectCourseService.InsertBySidAndCid(sid, cid);
        return r;
    }

    /**
     * 退课
     * @return
     */
    @PutMapping("/updateBySidAndCid2")
    public R UpdateBySidAndCid2(Integer id){
        R r = selectCourseService.UpdateBySidAndCid2(id);
        return  r;
    }

    /**
     * 根据学生id查列表
     * @param sid
     * @return
     */
    @GetMapping("/selectBysid")
    public R selectBysid(Integer sid){
        List<SelectCourse> selectCourses = selectCourseService.selectBysid(sid);
        return R.success(selectCourses,"查询成功");
    }

    /**
     * 根据课程id查询
     * @param cid
     * @return
     */
    @GetMapping("/selectBycid")
   public R selectBycid(Integer cid){
      List<SelectCourse> selectCourses = selectCourseService.selectBycid(cid);
        return R.success(selectCourses,"查询成功");
    }

    /**
     * 查询是否选课
     * @param sid
     * @param cid
     * @return
     */
    @GetMapping("/selectBySidAndCid")
    public R selectBySidAndCid(Integer sid, Integer cid){
        String select = selectCourseService.selectBySidAndCid(sid, cid);
        return R.success(select,"查询成功");
    }
    @GetMapping("/selectAll")
    public R selectAll(Integer end){
        List<SelectCourseDto> selectCourseDtos = selectCourseService.selectAll(end);
        return R.success(selectCourseDtos,"查询成功");
    }
}
